import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_application_1/pages/home/home_page.dart';
import 'package:flutter_application_1/pages/tab_page.dart';
import 'package:flutter_application_1/pages/web_view_page.dart';

// 路由管理类
class Routes {
  static Route<dynamic> generateRoute(RouteSettings settings) {
    switch (settings.name) {
      case RoutePath.tab:
        return pageRoute(TabPage(), settings: settings);
      case RoutePath.WebViewPage:
        return pageRoute(
            WebViewPage(
              title: '标题来的',
            ),
            settings: settings);
    }
    return pageRoute(Scaffold(
      body: SafeArea(
        child: Center(
          child: Text('页面不存在'),
        ),
      ),
    ));
  }

  static MaterialPageRoute pageRoute(
    Widget page, {
    RouteSettings? settings,
    bool? fullscreenDialog,
    bool? maintainState,
    bool? allowSnapshotting,
  }) {
    return MaterialPageRoute(
      builder: (context) => page,
      settings: settings,
      fullscreenDialog: fullscreenDialog ?? false,
      maintainState: maintainState ?? true,
      allowSnapshotting: allowSnapshotting ?? true,
    );
  }
}

class RoutePath {
  // 首页
  static const String tab = '/';
  // 详情页
  static const String WebViewPage = '/web_view_page';
}
